define(["jquery","bbcare",
        "scprit/department/vm/assessmentScreening/albertaAssessmentOfInfants.ui.js",
        "scprit/department/vm/assessmentScreening/assessmentScreeningQuestion.servers.js",
        "scprit/department/vm/assessmentScreening/albertaAssessmentOfInfants.event.js"],
    function ($,$bb,$ui,$servers, $event) {
        var page = {};
        page.init = function(){
            var getParams = $bb.getPageParams();
            var type = getParams.type;
            var userId = getParams.userId;
            var answerId = getParams.answerId,defaultCheck;
            var account=eval('('+sessionStorage.account+')');
            var accountName=account.alias;
            //患者信息展示：
            var infoParams = $servers.infoParams(userId);
            var infoFn = function(data){
                $(".patientName").html(data.data.PatientInfo.userName);
                $(".actualAge").html(data.data.ageMonDayStr);
                $(".checkDoctor").html(accountName);
                $(".checkDate").html($servers.getNowFormatDate());
            };
            $servers.getInfo(infoParams,infoFn);

            //问卷获取：
            var paramsQuestion = $servers.getParams(type,userId);
            var quesFn = function(data){
                if(answerId){
                    var answerResult = $.parseJSON(getParams.answer.answerResult);
                    var arr = [];
                    for(var item in data.data){
                       var answerItem = item == "俯卧位" ? "prone":item == "仰卧位" ? "dorsa":item == "坐位" ? "seats":"stand";
                       for(var i =0;i<data.data[item].length;i++){
                           var id = data.data[item][i].id;
                           if($.inArray(id,answerResult[answerItem]) != "-1"){
                               data.data[item][i].flag = true;
                               arr.push( answerItem+id );
                           }
                       }
                    }
                    $event.isChecked(arr);
                    $event.tab(data.data,arr);
                }
                 defaultCheck= $.trim($(".testSelect>div").eq(0).find("span.ques-tt").html());
                var dt = {
                    "type":$(".testSelect>div").eq(0).attr("title"),
                    "data":data.data[defaultCheck]
                };
                $ui.amisInit({"id":"#question","data":dt});
                $(".testSelect>div").eq(0).attr("class","checking");
                if(!answerId){
                    $event.scoreSubmit(data.data,type,userId);
                }else{
                    $event.viewReport({
                        "userId":userId,
                        "answerId":answerId,
                        "type":type
                    });
                }
            };
            $servers.getQuestion(paramsQuestion,quesFn);
        };
        return page;
    });